<!-- 考试  planMomth.jsp -->
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/common.jsp"%>
<html>
	<head>
		<script type="text/javascript" src="<%=contextPath%>/js/jquery.autogrow.js"></script> 
		<script type="text/javascript" src="<%=contextPath%>/ext3/adapter/ext/ext-base.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/ext3/ext-all.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/js/My97DatePicker/WdatePicker.js"></script>
		<link rel="stylesheet" type="text/css"	href="<%=contextPath%>/ext3/resources/css/ext-all.css">

		<script type="text/javascript" language="javascript"> 
		
			// 人行号
			var usernum = 0;
			<c:if test="${planMonthList != null || fn:length(planMonthList) != 0 }">
				usernum = ${fn:length(planMonthList)};
			</c:if>
			
			var bz = '<c:out value="${bz}"/>';
			
			$(document).ready (function() {
				//$('textarea.indispensable_left').autogrow();	
				$('textarea').autogrow();		
			});
				
			Ext.onReady(function(){
				var tb = new Ext.Toolbar({
			   		renderTo: document.all.tbar,
			    	items: [
				        {
				            text: '保存',
				            icon:"<%=contextPath%>/images/save.gif",
				            handler:comt,
				            hidden:<%= (!"".equals(request.getAttribute("bz")) || "1".equals(session.getAttribute("SESSION_ISADMIN"))) ? false:true%>
				        },'-',
				        {
				            text: '返回',
				            icon:"<%=contextPath%>/images/fanhui.png",
				            handler:function(){
				            	back();
				            }
				        }
			    	]
			    });
			});
			
			function toCheck() {
			
			}

		 </script>  
	</head>
	<body >
		<div id = "tbar"></div>
		<br>
		<form id="frmM" name="frmM" method="POST" >
			<table width="100%" id="listtab" class = "leadertab" >
				<tr>
					<th width="30">
						<c:if test="${bz != ''}">
							<img src="<%=contextPath%>/images/add.gif" onclick = "setHTML()" style="cursor:pointer"/></th>
						</c:if>
					<th width="60">班组</th>
					<th width="200">主要工作</th>
					<th width="50">责任人</th>
					<th width="60">计划时间</th>
					<th width="200">实施措施</th>
					<th >完成情况及未完成原因</th>
				</tr>

				<c:forEach items="${planMonthList}" var="detail" varStatus="status">
					<tr id='tr${status.index}' class = "repeat">
						<th width="30">
							<c:if test="${bz == detail.bz || '1' == isAdmin}">
								<img src="<%=contextPath%>/images/delete.gif" onclick = "delrow(this,${detail.id})" style="cursor:pointer"/></th>
							</c:if>
						<td width="60">
							<input type="text" style="width:100%" id="planMonthList[${status.index}].bz" name="planMonthList[${status.index}].bz" value = "${detail.bz}" readonly="true" />
						</td>
						<td width="300">
							<c:if test="${bz == detail.bz || '1' == isAdmin}">
								<textarea style="width:300px; height: 25px; min-height: 20px;line-height:15pt" id="planMonthList[${status.index}].zygz" name="planMonthList[${status.index}].zygz">${detail.zygz}</textarea>
									</c:if>
							<c:if test="${bz != detail.bz && '0' == isAdmin}">
								<textarea style="width:300px; height: 25px; min-height: 20px;line-height:15pt" id="planMonthList[${status.index}].zygz" name="planMonthList[${status.index}].zygz" readonly="true" >${detail.zygz}</textarea>
								</c:if>
						</td>
						<td width="50">
							<c:if test="${bz == detail.bz || '1' == isAdmin}">
							<textarea style="width:50px; height: 25px; min-height: 20px;line-height:15pt" id="planMonthList[${status.index}].fzr" name="planMonthList[${status.index}].fzr">${detail.fzr}</textarea>
								</c:if>
							<c:if test="${bz != detail.bz && '0' == isAdmin}">
								<textarea style="width:50px; height: 25px; min-height: 20px;line-height:15pt" id="planMonthList[${status.index}].fzr" name="planMonthList[${status.index}].fzr"   readonly="true">${detail.fzr}</textarea>
								</c:if>
						</td>
						<td width="70">
							<c:if test="${bz == detail.bz || '1' == isAdmin}">
								<input type="text" style="width:100%" 
									id="planMonthList[${status.index}].plandate" 
									name="planMonthList[${status.index}].plandate"  
									onclick="WdatePicker({dateFmt:'yyyy-MM-dd',el:$dp.$('planMonthList[${status.index}].plandate')})" 
									readonly="true" value='<fmt:formatDate value="${detail.plandate}" pattern="yyyy-MM-dd"/>' />
							</c:if>
							<c:if test="${bz != detail.bz && '0' == isAdmin}">
								<input type="text" style="width:100%" 
									id="planMonthList[${status.index}].plandate" 
									name="planMonthList[${status.index}].plandate"
									readonly="true" value='<fmt:formatDate value="${detail.plandate}" pattern="yyyy-MM-dd"/>' />
							</c:if>

						</td>
						<td width="300">
							<c:if test="${bz == detail.bz || '1' == isAdmin}">
								<textarea style="width:99%; height: 25px; min-height: 20px;line-height:15pt" id="planMonthList[${status.index}].sscs" name="planMonthList[${status.index}].sscs" >${detail.sscs}</textarea>
								<!--<input type="text" style="width:100%" id="planMonthList[${status.index}].sscs" name="planMonthList[${status.index}].sscs" value = "${detail.sscs}" maxlength="200"/>-->
							</c:if>
							<c:if test="${bz != detail.bz && '0' == isAdmin}">
								<textarea style="width:99%; height: 25px; min-height: 20px;line-height:15pt" id="planMonthList[${status.index}].sscs" name="planMonthList[${status.index}].sscs" readonly="true" >${detail.sscs}</textarea>
								<!--<input readonly="true" type="text" style="width:100%" id="planMonthList[${status.index}].sscs" name="planMonthList[${status.index}].sscs" value = "${detail.sscs}" readonly="true" />-->
							</c:if>
							
						</td>
                        <td >
							<c:if test="${bz == detail.bz || '1' == isAdmin}">
								<textarea style="width:99%; height: 25px; min-height: 20px;line-height:15pt" id="planMonthList[${status.index}].remark" name="planMonthList[${status.index}].remark" >${detail.remark}</textarea>
								<!--<input type="text" style="width:100%" id="planMonthList[${status.index}].remark" name="planMonthList[${status.index}].remark" value = "${detail.remark}" maxlength="200"/>-->
							</c:if>
							<c:if test="${bz != detail.bz && '0' == isAdmin}">
								<textarea style="width:99%; height: 25px; min-height: 20px;line-height:15pt" id="planMonthList[${status.index}].remark" name="planMonthList[${status.index}].remark" readonly="true" >${detail.remark}</textarea>
								<!--<input readonly="true" type="text" style="width:100%" id="planMonthList[${status.index}].remark" name="planMonthList[${status.index}].remark" value = "${detail.remark}" readonly="true" />-->
							</c:if>
							<input type="hidden" id="planMonthList[${status.index}].id" name="planMonthList[${status.index}].id" value = "${detail.id}"/>
						</td>   
					</tr>
				</c:forEach>
			
			</table>
		</form>
	</body>
</html>
<script language="javascript">

		String.prototype.endWith=function(str){
				if(str==null||str==""||this.length==0||str.length>this.length)
				return false;
				if(this.substring(this.length-str.length)==str)
				return true;
				else
				return false;
				return true;
		}

	 // 保存
     function comt(){
     
		var str1 = 0;
		var str2 = 0;
		var msg = "";
	
		for (var i = 0; i < frmM.elements.length; i++)
			{
				var e = frmM.elements[i];
				e.style.backgroundColor = "white";

				if ("text" == e.type || "textarea" == e.type) { //(e.name.endWith("date")) {
				    if (e.value == ""&&!e.name.endWith("remark")) {
				    	e.style.backgroundColor="yellow";
				    	++str1;
				    }
				}
				
				if ("textarea" == e.type && e.value.length > 200) {
					e.style.backgroundColor="red";
					++str2;
				}
				    
			}

		if (str1 > 0 || str2 > 0) {
			msg =  "黄色边框项目必须输入，红色边框最多输入200个汉字。";
		}
				
		if (msg.length > 0) {
			alert("系统检测到您的提交有以下错误：\t\t\t\t\n" + msg);
			return;
		}

     	document.frmM.action = "<%=contextPath%>/planMonth!save.do";
     	document.frmM.submit();
     }
     
     // 返回
     function back() {
     	document.frmM.action = "<%=contextPath%>/planMonthList!getList.do";
		document.frmM.submit();
     }
	 
	 // 增加行
	 function setHTML() {
	 
	 	var temp = "WdatePicker({dateFmt:'yyyy-MM-dd',el:$dp.$('planMonthList[" + usernum + "].plandate')})";

		var str = 	'<tr id = '+ usernum +' class = "repeat">' +
					'<td width="30"><img src="/DLMIS/images/delete.gif" onclick = "delrow(this,0)" style="cursor:pointer"/></td>' + 
					'<td width="0"><input style="width:100%" type="text" id=planMonthList['+ usernum + '].bz name=planMonthList['+ usernum + '].bz value="' + bz + '" readonly="true" /></td >' +
					'<td width="300"><textarea style="width:300px; height: 25px; min-height: 20px;line-height:15pt"  id=planMonthList['+ usernum + '].zygz name=planMonthList['+ usernum + '].zygz ></textarea></td >' +
					'<td width="50"><textarea style="width:50px; height: 25px; min-height: 2px;line-height:15pt" id=planMonthList['+ usernum + '].fzr name=planMonthList['+ usernum + '].fzr ></textarea></td >' +
					'<td width="70"><input  onclick="' + temp + '" style="width:100%" type="text" id=planMonthList['+ usernum + '].plandate name=planMonthList['+ usernum + '].plandate readonly="true" /></td >' +
                    '<td width="300"><textarea style="width:99%; height: 25px; min-height: 20px;line-height:15pt"  id=planMonthList['+ usernum + '].sscs name=planMonthList['+ usernum + '].sscs ></textarea>' +
					'<td><textarea style="width:99%; height: 25px; min-height: 20px;line-height:15pt"  id=planMonthList['+ usernum + '].remark name=planMonthList['+ usernum + '].remark ></textarea>' +
					'<input type="hidden" id=planMonthList['+ usernum + '].id name=planMonthList['+ usernum + '].id value ="0"></td >' +
					'</tr>';
					
		$('table.leadertab').append(str);	
				
		usernum++;
		
		// 重新付序号
//		var n = 0;		
//		for (var index=0;index<usernum; index++) {
//			if (document.getElementById("td" + index) != null && document.getElementById("td" + index) != undefined) {
//				++n;
//				document.getElementById("td" + index).innerHTML = n;
//			}
//		}				
//	 }

		$('textarea').autogrow();	
	
	}
	
	//删除一行（已有数据）
	function delrow(row,id){


		if (confirm("确定要删除该工作计划吗？")) {
			if(id != 0) {
				Ext.Ajax.request({
					method :'POST',
					url :'planMonth!deletePlanDetail.do?id=' + id,
					params : {},
					success : function(response, options) {
						var obj = Ext.decode(response.responseText);
						Ext.MessageBox.alert('提示', obj["msg"]);
					
	   					$(row).parents(".repeat").remove();	

					},
					failure : function(response, options) {
						Ext.MessageBox.alert('提示 ', '删除失败。');
					}
				});
			} else {
				$(row).parents(".repeat").remove();	
			}

		}

	} 
</script>